package nc.bs.medpub.sourcebill;

import nc.bs.pf.pub.PfDataCache;
import nc.bs.pub.pf.PfUtilTools;
import nc.bs.scm.sourcebill.SCMDefaultDatafinder;
import nc.bs.trade.billsource.BillTypeSetDataFinder;
import nc.bs.trade.billsource.DefaultBillFinder;
import nc.bs.trade.billsource.IBillDataFinder;
import nc.bs.trade.billsource.NullDataFinder;
import nc.vo.pf.change.PfUtilBaseTools;
import nc.vo.pub.billtype.BilltypeVO;

public class MedForScmBillFinder extends DefaultBillFinder {

	@Override
	public IBillDataFinder createBillDataFinder(String billType) throws Exception {

		BilltypeVO btVO = PfDataCache.getBillTypeInfo(billType);
		BilltypeVO type = null;
		if (btVO != null) {
			billType = PfUtilBaseTools.getRealBilltype(billType);
			type = PfDataCache.getBillType(billType);
		}

		if (type == null)
			return new NullDataFinder();

		IBillDataFinder finder = null;

		String datafinderclassname = type.getDatafinderclz();

		if (datafinderclassname != null) {
			finder = (IBillDataFinder) PfUtilTools.instantizeObject(billType, datafinderclassname);
		} else if (type.getForwardbilltype() != null)
			finder = new BillTypeSetDataFinder();
		else
			finder = new SCMDefaultDatafinder();

		return finder;
	}

}
